<?php

namespace App\Member\Controllers;

use App\Admin\Repositories\Deposite;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Admin;
use App\Models\Deposite as DepositeModels;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Row;



class DepositeController extends BaseController
{

    //protected $title = trans('deposite.fields.zcrjxxxx'); //'投入记录';


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Deposite(['admin_user']), function (Grid $grid) {
            $grid->tableCollapse(false);
            $grid->setActionClass(Grid\Displayers\ContextMenuActions::class);

            $grid->model()->where('user_id',Admin::user()->id);
            $grid = $this->gridButton($grid, false);
            $grid->column('admin_user.name',trans('deposite.fields.name'));
            $grid->column('admin_user.username',trans('deposite.fields.username'));
            $grid->column('admin_user.mt_login',trans('deposite.fields.mt_login'))->display(function ($q) {
                return $q ?? '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            });
            $grid->usd_amount;
            $grid->type->using(
                [
                    1=>trans('deposite.fields.zcrjxxxx'),//正常投入
                    2=>trans('deposite.fields.zsrjxxxx'),//赠送投入
                ]
            )->label([1=>'success',2=>'primary']);
            $grid->created_at;

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }


    /***
     *  重构显示页面 用Tab 方式显示多页面
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('投入记录')
            // body 方法可以接受 Laravel 的视图作为参数
            ->row(function (Row $row) use ($id) {
                $row->column(6, function (Column $column) use ($id)  {
                    $column->append($this->detail($id));
                });
            });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Deposite(['admin_user']), function (Show $show) {

            $show->field('admin_user.name',trans('deposite.fields.name'));
            $show->field('admin_user.username',trans('deposite.fields.username'));
            $show->field('admin_user.mt_login',trans('deposite.fields.mt_login'));
            $show = $this->showButton($show);
            //$show->showRefreshButton(); 刷新按钮
            $show->usd_amount;
            $show->type->using([
                '1' => trans('deposite.fields.zcrjxxxx'),//正常投入
                '2' => trans('deposite.fields.zsrjxxxx'),//赠送投入
            ])->label();
            $show->created_at;
        });
    }



    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Deposite(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('usd_amount');
            $form->text('tyep');
            $form->text('admin_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }

}
